package com.ruoyi.web.controller.project;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.Material;
import com.ruoyi.system.service.IMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 材料Controller
 * 
 * @author ruoyi
 * @date 2025-03-11
 */
@RestController
@RequestMapping("/material")
@RequiredArgsConstructor
@Api(tags = "材料")
public class MaterialController extends BaseController{

    private final IMaterialService materialService;


    @GetMapping("/list")
    @ApiOperation("查询材料列表")
    public TableDataInfo list(@RequestParam(value = "name",required = true)String name)
    {
        startPage();
        QueryWrapper<Material> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(name)){
            wrapper.like("name",name);
        }
        List<Material> list = materialService.list(wrapper);
        return getDataTable(list);
    }



    @GetMapping(value = "/{id}")
    @ApiOperation("获取材料详细信息")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(materialService.getById(id));
    }


    @Log(title = "材料", businessType = BusinessType.INSERT)
    @ApiOperation("新增材料")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Material Material)
    {
        return toAjax(materialService.save(Material));
    }


    @Log(title = "材料", businessType = BusinessType.UPDATE)
    @ApiOperation("修改材料")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody Material Material)
    {
        return toAjax(materialService.updateById(Material));
    }


    @Log(title = "材料", businessType = BusinessType.DELETE)
    @ApiOperation("删除材料")
	@PostMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(materialService.removeBatchByIds(Arrays.asList(ids)));
    }
}
